package com.itheima.controller;

import com.itheima.config.RedisProperties;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import com.itheima.vo.UserOrderVo;
import org.feign.client.OrderFeign;
import org.feign.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    @Resource
    private OrderFeign orderFeign;
    @Autowired
    private RedisProperties redisProperties;

    @GetMapping("/findUserById/{username}")
    public Map findUserById(@PathVariable("username") String username) {
        User user = userService.findUserById(username);
        List orderList = orderFeign.findOrderByUserId(username);
        Map map = new HashMap();
        UserOrderVo userOrderVo = new UserOrderVo();
        userOrderVo.setUser(user);
        userOrderVo.setOrderList(orderList);
        map.put(username, userOrderVo);
        return map;
    }

    //用来测试配置中心是否配置成功
    @GetMapping("/hello")
    public RedisProperties disUserById(){
        return redisProperties;
    }
}
